package com.yq.day18.demo;

/**
 * @author 3307235355@qq.com
 * @since 2022/06/19 16:34
 */
public class Demo01 {
    public static void main(String[] args) {
        NoNum n1 = () -> System.out.println("test");
        n1.test();

        NoNum n21 = () -> myTest2();
        n21.test();

        NoNum n2 = Demo01::myTest2;
        n2.test();

        NoNum n3 = () -> new Demo01().myTest();
        n3.test();
        NoNum n4 = new Demo01()::myTest;
        n4.test();


        System.out.println("=============");
        NoNumTwo t1 = (a,b)->myTest3(a,b);
        System.out.println(t1.test(10, 20));

        NoNumTwo t2 = Demo01::myTest3;
        System.out.println(t2.test(30, 40));

        System.out.println("=============");
        NoNumTwo t3 = (a,b)->new Demo01().myTest4(a,b);
        System.out.println(t3.test(12, 15));

        NoNumTwo t4 = new Demo01()::myTest4;
        System.out.println(t4.test(45, 78));


    }

    // 匿名内部类调用外部的成员方法和静态的方法
    public void myTest() {
        System.out.println("我是外部类的成员方法");
    }

    public static void myTest2() {
        System.out.println("我是外部类的静态成员方法！！！！");
    }

    public static int myTest3(int a, int b) {
        System.out.println("我是外部类的静态成员方法！！！！");
        System.out.println("a+b="+(a+b));
        return 666;
    }

    public int myTest4(int a, int b) {
        System.out.println("我是外部类的成员方法！！！！");
        return 77777;
    }
}

@FunctionalInterface
interface NoNum {
    void test();
}

@FunctionalInterface
interface NoNumTwo {
    int test(int a, int b);
}